// import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/reset.css';
import axios from 'axios';
import { useUserStore } from './stores/user';
import utils from '@/utils/utils.js';
import createPersistedState from 'pinia-plugin-persistedstate';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
const app = createApp(App)

axios.defaults.baseURL = 'http://127.0.0.1:8088';
app.config.globalProperties.$baseURL = 'http://127.0.0.1:8088';

const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);
app.use(pinia)
app.use(router)
app.use(Antd)

app.mount('#app')

const userStore  = useUserStore()
/**
 * axios拦截器
 */
axios.interceptors.request.use(function (config) {
    // console.log('请求参数：', config);
    const token = userStore.user.token;
    if (!utils.isEmpty(token)) {
        config.headers.token = token;
        // console.log("请求headers增加token:", token);
    }
    return config;
}, error => {
    return Promise.reject(error);
});
//
// axios.interceptors.response.use(function (response) {
//     console.log('返回结果：', response);
//     return response;
// }, error => {
//     console.log('返回错误：', error.message);
//     return Promise.reject(error);
// });
